package kim.artemis.rpc.core.loadbalance;

import java.util.Random;
import java.util.TreeSet;

/**
 * 负载均衡随机策略
 * @author Wq.
 */
public class ArtemisRpcLoadBalanceRandom extends ArtemisRpcLoadBalance {

    private Random random = new Random();

    @Override
    public String route (String serviceKey, TreeSet<String> addressSet) {
        String[] socketAddressArr = addressSet.toArray(new String[addressSet.size()]);
        return socketAddressArr[random.nextInt(addressSet.size())];
    }
}
